package com.jinunn.system.controller;

import com.jinunn.system.common.enums.LogModuleEnum;
import com.jinunn.system.common.result.Result;
import com.jinunn.system.model.params.LoginUserParam;
import com.jinunn.system.model.vo.LoginVo;
import com.jinunn.system.plugin.syslog.annotation.LogAnnotation;
import com.jinunn.system.service.AuthService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author Jindun
 * @version AuthController.java, v0.1 2024年 07⽉ 10⽇  下午5:32 Jindun Exp $
 */
@Tag(name = "认证中心")
@RestController
@RequestMapping("/api/v1/auth")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class AuthController {

    private final AuthService authService;

    @Operation(summary = "登录")
    @PostMapping("/login")
    @LogAnnotation(value = "登录", module = LogModuleEnum.LOGIN)
    public Result<LoginVo> login(@RequestBody @Validated LoginUserParam userParam) {
        LoginVo loginResult = authService.login(userParam);
        return Result.success(loginResult);
    }

    @Operation(summary = "注销")
    @DeleteMapping("/logout")
    public <T> Result<T> logout() {
        authService.logout();
        return Result.success();
    }
}
